<% @revisions = Roroacms::Post.where(:ancestry => @record.id.to_s, :post_type => 'autosave').order('created_at desc') %>

<% if @revisions.blank? || @record.id.blank? || @revisions.size <= 1 %>

  <div class="text-center top-margin-20">
    <strong class="text-center"><%= t("views.admin.partials.revision_tree.no_revisions") %></strong>
  </div>

<% else %>

  <ul class="timeline-single">


      <%
      @revisions.each_with_index do |f, index| %>

        <!-- need to check against the last user-autosave record instead of the revision -->

        <% break if index == 5 %>
        <li>

          <% if f.post_status.downcase == 'user-autosave' || f.post_type.downcase == 'page' %>
            <div class="timeline-single-badge"><i class="fa fa-user"></i></div>
          <% else %>
            <div class="timeline-single-badge"><i class="fa fa-save"></i></div>
          <% end %>

          <% check =  get_closest_revision(@revisions, index, f.post_status.downcase) %>
          
          <div class="timeline-single-panel">

            <div class="timeline-single-heading">
              <h4 class="timeline-single-title">
                <label><%= t("views.admin.partials.revision_tree.post_title") %></label>
                <%= Diffy::Diff.new(check.blank? ? "\r\n" : "#{check.post_title.to_s}", f.post_title, :include_plus_and_minus_in_html => true, :allow_empty_diff => false ).to_s(:html).html_safe %>
              </h4>
                <h4>
                  <label><%= t("views.admin.partials.revision_tree.url") %></label>
                  <%= Diffy::Diff.new(check.blank? ? "\r\n" : "/#{check.post_slug.to_s}", '/' + f.post_slug, :include_plus_and_minus_in_html => true, :allow_empty_diff => false ).to_s(:html).html_safe %>
                </h4>
            </div>

            <div class="timeline-single-body">
                <label><%= t("views.admin.generic.content") %></label>
                <%= Diffy::Diff.new(check.blank? ? "\r\n" : "#{check.post_content.to_s}", "#{f.post_content.to_s}", :include_plus_and_minus_in_html => true, :allow_empty_diff => false).to_s(:html_simple).html_safe %>
              <hr>
              <div class="btn-group">
                <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                  <i class="fa fa-cog"></i> <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" role="menu">
                  <li>
                    <%= link_to restore_admin_revision_path(f) do %>
                      <i class="fa fa-magic"></i> <%= t("views.admin.generic.restore") %>
                    <% end %>   
                  </li>
                  <li>
                    <%= link_to edit_admin_revision_path(f) do %>
                      <i class="fa fa-search"></i> <%= t("views.admin.partials.revision_tree.compare") %>  
                    <% end %>
                  </li>
                </ul>
              </div>
              <small class="text-muted pull-right"><i class="fa fa-clock-o"></i> <%= time_ago_in_words(f.updated_at) %> ago by <%= (!f.admin.blank? && ( f.post_status.downcase == 'user-autosave' || f.post_type.downcase == 'page' ) ) ? f.admin.username : t("views.admin.generic.system") %></small>
            </div>

          </div>

        </li>

      <% end %>

  </ul>
  
  <%= link_to edit_admin_revision_path(@revisions.first.id), :class => 'btn btn-primary btn-block btn-sm pull-right view-all-revisions' do %>
    <i class="fa fa-search"></i> <%= t("views.admin.partials.revision_tree.view_all") %> 
  <% end %>

<% end %>